 /*
 * @name: 自营商品列表
 * @Author: along
 * @Date: 2019-07-21
 * @Last Modified by: along
 * @Last Modified time: 2020-07-22
 */
<template>
    <div class="container goodsBargList">
        <!-- header -->
        <div class="header-nav">
            <div class="header-left">
                <div class="header-new-box">
                    <p class="header-new-box-title">商品名称:</p>
                    <el-input
                        v-model="head.goods_title"
                        placeholder="请输入内容"
                        size="small"
                        clearable
                        suffix-icon="el-icon-search"
                        @change="getTableData(1)"
                        @keyup.native.enter="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">店铺名称:</p>
                    <el-input
                        v-model="head.shop_title"
                        placeholder="请输入内容"
                        size="small"
                        clearable
                        suffix-icon="el-icon-search"
                        @change="getTableData(1)"
                        @keyup.native.enter="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">公司名称:</p>
                    <el-input
                        v-model="head.company_name"
                        placeholder="请输入内容"
                        size="small"
                        clearable
                        suffix-icon="el-icon-search"
                        @change="getTableData(1)"
                        @keyup.native.enter="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">审核状态:</p>
                    <el-select
                        v-model="head.audit_status"
                        clearable
                        filterable
                        placeholder="请选择"
                        size="small"
                        @change="getTableData(1)"
                    >
                        <el-option
                            v-for="item in auditList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        />
                    </el-select>
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">显示状态:</p>
                    <el-select
                        v-model="head.goods_status"
                        clearable
                        filterable
                        placeholder="请选择"
                        size="small"
                        @change="getTableData(1)"
                    >
                        <el-option
                            v-for="item in showList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        />
                    </el-select>
                </div>
            </div>
        </div>
        <!-- /header -->

        <!-- table -->
        <el-table
            :data="tableData"
            height="100%"
            style="width: 100%;"
            border
            ref="goodsBargList"
            @sort-change="handleSortChanged"
            @select="fnSelect"
            @select-all="fnSelectAllTop"
            @selection-change="handleSelectionChange"
            v-loading="loading"
        >
            <el-table-column
                type="selection"
                width="40"
                fixed="left"
            />
            <el-table-column
                type="index"
                width="80"
                label="序号"
                align="left"
            />
            <el-table-column
                prop="goods_title"
                label="商品名称"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            />
            <el-table-column
                prop="goods_cover"
                label="商品缩略图"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
                :width="100"
            >
                <template slot-scope="scope">
                    <img
                        :src="scope.row.goods_cover"
                        alt="加载失败"
                        @click="fnShowPreview(scope.row.goods_cover)"
                        style="width:40px;height:40px"
                    >
                </template>
            </el-table-column>
            <el-table-column
                prop="goods_no"
                label="商品编号"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
                :width="160"
            />
            <el-table-column
                prop="company_name"
                label="公司名称"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
                :width="160"
            />
            <el-table-column
                prop="shop_title"
                label="店铺名称"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
                :width="140"
            />
            <el-table-column
                prop="bargain_duration"
                label="持续砍价时间"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
                :width="150"
            >
                <template slot-scope="scope">
                    <p v-if="scope.row.bargain_duration">
                        {{ scope.row.bargain_duration | setBargain }}
                    </p>
                    <p v-else>
                        --
                    </p>
                </template>
            </el-table-column>
            <el-table-column
                prop="goods_price"
                label="最低低价"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
                :width="140"
            />
            <el-table-column
                prop="goods_price_origin"
                label="原价"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            />
            <el-table-column
                prop="goods_stock"
                label="剩余库存"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            />
            <el-table-column
                prop="goods_sale"
                label="总销量"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
                sortable
                :width="100"
            />
            <el-table-column
                prop="goods_view"
                label="总浏览量"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
                sortable
                :width="100"
            />
            <el-table-column
                prop="create_time"
                label="创建日期"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
                sortable
                :width="140"
            >
                <template slot-scope="scope">
                    {{ scope.row.create_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm') }}
                </template>
            </el-table-column>
            <el-table-column
                label="砍价记录"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
                :width="100"
            >
                <template slot-scope="scope">
                    <p
                        @click="fnHandleCheck(1, scope.row)"
                        class="cursor-font"
                    >
                        查看
                    </p>
                </template>
            </el-table-column>
            <el-table-column
                prop="goods_sort"
                label="排序"
                sortable
            >
                <template slot-scope="scope">
                    <div class="sort-wrap">
                        {{ scope.row.goods_sort }}
                        <span class="sort-spliter" />
                        <el-button
                            type="text"
                            class="btn-sort"
                            @click="fnEditSort(scope.row)"
                        >
                            <i class="el-icon-edit" />
                        </el-button>
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                prop="audit_status"
                label="审核状态"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            >
                <template slot-scope="scope">
                    <div class="zd-audit-wrap">
                        <p :class="scope.row.audit_status == 1 ? 'wrap-success' : (scope.row.audit_status == -1 ? 'wrap-error' : 'wrap-loading')" />
                        <p v-if="scope.row.audit_status == 1">已通过</p>
                        <p v-if="scope.row.audit_status == -1">未通过</p>
                        <p v-if="scope.row.audit_status == 0">待审核</p>
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                prop="goods_status"
                label="显示状态"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            >
                <template slot-scope="scope">
                    <el-switch
                        v-model="scope.row.goods_status"
                        :active-value="1"
                        :inactive-value="0"
                        @change="fnChangeActive(scope.row)"
                    />
                </template>
            </el-table-column>
            <el-table-column
                label="操作"
                align="center"
                fixed="right"
                :width="170"
            >
                <template slot-scope="scope">
                    <div style="display:flex;flex-wrap:wrap">
                        <el-button
                            type="text"
                            class="curse-add"
                            :style="{marginRight: '15px'}"
                            :disabled="scope.row.audit_status == 1"
                            @click="fnSetAuditSuccess(scope.row)"
                        >
                            审核通过
                        </el-button>
                        <el-button
                            type="text"
                            class="curse-add"
                            :style="{marginRight: '0px'}"
                            :disabled="scope.row.audit_status == -1"
                            @click="fnSetAuditError(scope.row)"
                        >
                            审核不通过
                        </el-button>
                        <el-button
                            type="text"
                            class="curse-add"
                            :style="{marginRight: '15px'}"
                            @click="fnSetLimit(scope.row)"
                        >
                            设置限制
                        </el-button>
                        <el-button
                            type="text"
                            class="curse-add"
                            :style="{marginRight: '15px'}"
                            @click="fnEditShop(scope.row)"
                        >
                            编辑
                        </el-button>
                    </div>
                </template>
            </el-table-column>
        </el-table>
        <!-- /table -->

        <!-- /分页 -->
        <div class="pagination-wrapper clearfix">
            <el-checkbox
                v-model="checkedAll"
                :indeterminate="checkIndeterminate"
                @change="fnChangeChecked"
            >全选</el-checkbox>
            <el-button
                type="text"
                :disabled="multipleSelection.length == 0 ? true : false"
                @click="fnAuditSuccess()"
            >批量审核通过</el-button>
            <el-pagination
                background
                layout="total, prev, pager, next"
                :current-page.sync="page.now_page"
                :total="page.total_count"
                :page-size="page.page_size"
                @current-change="getTableData"
            />
        </div>

        <!-- 图片预览 -->
        <img-preview ref="preview" />

        <!-- 砍价记录 -->
        <el-dialog
            title="砍价记录"
            :visible.sync="dialogBarg"
            width="828px"
            :close-on-click-modal="false"
        >
            <el-table
                :data="dataList"
                height="100%"
                style="width: 100%;max-height: 550px"
                border
            >
                <el-table-column
                    type="index"
                    width="80"
                    label="序号"
                    align="center"
                />
                <el-table-column
                    prop="true_name"
                    label="用户姓名"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                    align="center"
                />
                <el-table-column
                    prop="student_no"
                    label="用户编号"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                    align="center"
                />
                <el-table-column
                    prop="start_time"
                    label="开始时间"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                    align="center"
                    :width="140"
                >
                    <template slot-scope="scope">
                        {{ scope.row.start_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm') }}
                    </template>
                </el-table-column>
                <el-table-column
                    prop="is_buy"
                    label="是否购买"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                    align="center"
                >
                    <template slot-scope="scope">
                        <p v-if="scope.row.is_buy == 1">是</p>
                        <p v-if="scope.row.is_buy == 0">否</p>
                    </template>
                </el-table-column>
                <el-table-column
                    prop="bargain_times"
                    label="帮砍次数"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                    align="center"
                />
            </el-table>
            <div class="pagination-wrapper clearfix">
                <el-pagination
                    background
                    layout="total, prev, pager, next"
                    :current-page.sync="logPage.now_page"
                    :total="logPage.total_count"
                    :page-size="logPage.page_size"
                    @current-change="fnHandleCheck"
                />

            </div>
        </el-dialog>

        <!-- 设置砍价次数 -->
        <el-dialog
            title="设置砍价次数"
            :visible.sync="dialogBargNumber"
            width="680px"
            :close-on-click-modal="false"
            :show-close="false"
            class="dialogBargNumber"
        >
            <div class="wrap">
                <el-form
                    :model="ruleForm"
                    :rules="rules"
                    ref="ruleForm"
                    label-width="100px"
                    class="demo-ruleForm"
                    :label-position="'right'"
                >
                    <el-form-item
                        label="需砍次数:"
                        prop="bargain_times"
                    >
                        <div class="wrap-time">
                            <el-input
                                v-model="ruleForm.bargain_times"
                                placeholder="请输入帮砍次数"
                                size="small"
                                v-inserted
                                max="10"
                                min="1"
                                maxlength="2"
                                :style="{width: '350px'}"
                            />
                            <p class="wrap-tips">
                                次
                            </p>
                            <el-button
                                size="small"
                                type="primary"
                                plain
                                :style="{width: '100px', height: '32px', marginLeft: '30px'}"
                                @click="fnSetProduct(ruleForm.bargain_times)"
                            >
                                批量填充
                            </el-button>
                        </div>
                        <el-table
                            :data="ruleForm.bargain_product_json"
                            max-height="300px"
                            style="width: 100%;margin-top:24px"
                            border
                        >
                            <el-table-column
                                prop="spec_list"
                                label="规格"
                                show-overflow-tooltip
                                :formatter="emptyFormatter"
                                align="center"
                            >
                                <template slot-scope="scope">
                                    <div class="spec-list-wrap">
                                        <div
                                            v-for="(item,index) in scope.row.spec_list"
                                            :key="index"
                                            class="spec-list"
                                        >
                                            {{ item.spec_name + ':' + item.spec_value + ';' }}
                                        </div>
                                    </div>
                                </template>
                            </el-table-column>
                            <el-table-column
                                prop="bargain_times"
                                label="需砍次数"
                                show-overflow-tooltip
                                :formatter="emptyFormatter"
                                align="center"
                            >
                                <template slot-scope="scope">
                                    <el-input
                                        v-model="scope.row.bargain_times"
                                        size="small"
                                    />
                                </template>
                            </el-table-column>
                        </el-table>
                    </el-form-item>
                    <el-form-item
                        label="商品限购:"
                        prop="bargain_limit"
                    >
                        <div class="wrap-time">
                            <el-input
                                v-model="ruleForm.bargain_limit"
                                placeholder="请输入限购次数"
                                size="small"
                                v-inserted
                                max="10"
                                min="1"
                                maxlength="2"
                                :style="{width: '473px'}"
                            />
                            <p class="wrap-tips">
                                次
                            </p>
                        </div>
                    </el-form-item>
                    <el-form-item
                        label="砍价持续时间:"
                    >
                        <!-- prop="bargain_duration" -->
                        <div class="wrap-time">
                            <el-input-number
                                v-model="exprice.date"
                                controls-position="right"
                                :min="0"
                                :max="5"
                                size="small"
                                v-inserted
                                class="wrap-time-day"
                            />
                            <p class="wrap-time-dw">(天)</p>
                            <el-time-picker
                                v-model="exprice.second"
                                :picker-options="{
                                    selectableRange: '00:00:00 - 23:59:59'
                                }"
                                placeholder="任意时间点"
                                size="small"
                                :style="{width: '210px', marginLeft: '65px'}"
                            />
                            <p class="wrap-time-dw">(小时)</p>
                        </div>
                    </el-form-item>
                </el-form>
                <div class="wrap-button">
                    <el-button
                        type="default"
                        size="small"
                        :style="{width: '100px', height: '32px'}"
                        @click="dialogBargNumber = false"
                    >
                        取消
                    </el-button>
                    <el-button
                        type="primary"
                        size="small"
                        :style="{width: '100px', height: '32px', marginLeft: '60px'}"
                        @click="fnSetBain('ruleForm')"
                    >
                        确定
                    </el-button>
                </div>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import imgPreview from '@/components/common/img-preview';
import { back } from '@/mixin/back';
export default {
    mixins: [back],
    components: {
        imgPreview
    },
    data () {
        const validateSpec = (rule, value, callback) => {
            let list = this.ruleForm.bargain_product_json;

            let flag = true;

            for(let key=0; key<list.length; key++){
                if(Number(list[key].bargain_times) == 0) {
                    flag = false;
                }
            }
            if(flag) {
                callback();
            } else {
                callback(new Error('请填写正确的次数'));
            }
        };

        return {
            exprice: {
                date: '',// 天数
                second: ''//小时
            },
            ruleForm: {
                bargain_duration: '',
                bargain_times: '',
                bargain_limit: '',
                bargain_product_json: []
            },
            rules: {
                bargain_duration: [
                    { required: true, message: '请选择砍价持续时间', trigger: 'change' }
                ],
                bargain_times: [
                    { required: true, message: '请输入需砍次数', trigger: 'blur' },
                    { validator: validateSpec, trigger: 'blur' },
                ],
                bargain_limit: [
                    { required: true, message: '请输入限购次数', trigger: 'change' }
                ]
            },
            hire_no: '',
            dialogBargNumber: false,//设置砍价次数弹窗开关
            goods_no: '',//商品编辑记录设置砍价次数时使用
            dialogBarg: false,//砍价记录弹窗开关
            dataList: [],//砍价记录数据
            checkIndeterminate: false,
            multipleSelection: [],
            checkedAll: false,
            head: {
                goods_title: '',
                shop_title: '',
                company_name: '',
                audit_status: '',
                goods_status: ''
            },
            auditList: [{value: '',label: '全部'},{value: 0,label: '待审核'},{value: -1,label: '未通过'},{value: 1,label: '已通过'}],
            showList: [{value: '',label: '全部'},{value: 1,label: '已显示'},{value: 0,label: '已隐藏'}],
            filterData: {
                sort_field: 'asc',
                sort_type: 'desc'
            },
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 0
            },
            logPage: {
                now_page: 1,
                total_count: 0,
                page_size: 0
            },
            tableData: [],
            authResult: {},
            loading: false
        };
    },
    filters: {
        setBargain (val) {
            let hous = Math.floor(val / 60 / 60 / 24);
            let scend = val - hous * 86400;
            let min_total = Math.floor(scend / 60);
            let sec = Math.floor(scend % 60);
            let hour_total = Math.floor(min_total / 60);
            let min = Math.floor(min_total % 60);

            return (hous ? hous + '天' : '') + hour_total + '小时' + min + '分钟' + sec + '秒';
        }
    },
    computed: {},
    directives: {
        inserted (el, binding, vnode, oldVnode) {
            el.addEventListener("keypress", e => {
                let event = e || window.event;
                let charcode = typeof event.charCode === 'number' ? event.charCode : event.keyCode;
                let re = /\d/;

                if(!re.test(String.fromCharCode(charcode)) && charcode > 9 && !event.ctrlKey){
                    if(event.preventDefault){
                        event.preventDefault();
                    }else{
                        event.returnValue = false;
                    }
                }
            });
        }
    },
    watch: {
        exprice: {
            handler: function (val, oldVal) {//处理持续时间选择
                let dateTemp = Number(val.date) * 86400;
                let screndHous = new Date(val.second).getHours();
                let screndMinut = new Date(val.second).getMinutes();
                let scrend = new Date(val.second).getSeconds();
                let bargain_duration = dateTemp + screndHous * 60 * 60 + screndMinut * 60 + scrend;

                this.$set(this.ruleForm, 'bargain_duration', bargain_duration);
            },
            deep: true
        }
    },
    mounted () {
        this.authResult = this.$route.meta.authResult;
        this.getTableData();

        //打开编辑弹窗
        this.getUrl();
    },
    methods: {
        /**
         * 获取表格数据
         */
        getTableData (page) {
            this.loading = true;
            this.$post('/student/shop_goods_bargain%5Cget_list', {
                page_id: page || this.page.now_page,
                ...this.head,
                hire_no: this.hire_no,
                sort_field: this.filterData.sort_field,
                sort_type: this.filterData.sort_type
            }, resp => {
                if (resp.code == 1) {
                    this.tableData = resp.data.list;
                    this.page.now_page = resp.data.page.now_page;
                    this.page.total_count = resp.data.page.total_count;
                    this.page.page_size = resp.data.page.page_size;
                }
            });

            setTimeout(()=>{
                this.loading = false;
            },500);
        },

        /**
         * 参数处理
         */
        getUrl () {
            let query = this.$route.query;

            if(query.goods_no && query.showDialog) {
                this.fnSetLimit({
                    goods_no: query.goods_no
                });
            }
        },

        /**
         * 排序
         */
        fnEditSort (row) {
            this.$prompt('请输入排序号', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                inputPattern: /^([1-9]\d?|[1-9]\d+)$/,
                inputErrorMessage: '排序号格式不正确,请重新输入'
            }).then(({ value }) => {
                this.$post('/student/shop_goods%5Cmodify',{
                    goods_no: row.goods_no,
                    goods_sort: value
                },resp=>{
                    if (resp.code == 1) {
                        this.getTableData();
                        this.$message({
                            type: 'success',
                            message: '操作成功'
                        });
                    } else if (resp.code == 0) {
                        this.$message({
                            type: 'warning',
                            message: resp.msg
                        });
                    }
                });
            });
        },

        /**
         * 批量审核通过
         */
        fnAuditSuccess () {
            this.multipleSelection.forEach(option => {
                this.$post('/student/shop_goods%5Caudit',{
                    action: 'pass',
                    goods_no: option.goods_no
                },resp=>{
                    if (resp.code == 1) {
                        //
                    } else if (resp.code == 0) {
                        this.$message({
                            type: 'warning',
                            message: resp.msg
                        });
                    }
                });
            });

            setTimeout(()=>{
                this.$message({
                    type: 'success',
                    message: '审核通过'
                });
                this.getTableData();
            },400);
        },

        /**
         * 获取砍价记录数据
         */
        fnHandleCheck (page, row) {
            this.$post('/student/shop_goods_bargain%5Cget_log_list',{
                goods_no: row.goods_no,
                page_id: page || this.logPage.now_page,
            },resp=>{
                if (resp.code == 1) {
                    this.dataList = resp.data.list;
                    this.logPage.now_page = resp.data.page.now_page;
                    this.logPage.total_count = resp.data.page.total_count;
                    this.logPage.page_size = resp.data.page.page_size;
                    this.dialogBarg = !this.dialogBarg;
                } else if (resp.code == 0) {
                    this.$message({
                        type: 'warning',
                        message: resp.msg
                    });
                }
            });
        },

        /**
         * 上架/下架
         */
        fnChangeActive (row) {
            this.$post('/student/shop_goods%5Cset_status',{
                goods_no: row.goods_no,
                status: row.goods_status == 1 ? 1 : -1
            },resp=>{
                if (resp.code == 1) {
                    this.getTableData();
                    this.$message({
                        type: 'success',
                        message: '操作成功'
                    });
                } else if (resp.code == 0) {
                    this.$message({
                        type: 'warning',
                        message: resp.msg
                    });
                }
            });
        },

        /**
         * 审核通过
         */
        fnSetAuditSuccess (row) {
            this.$post('/student/shop_goods%5Caudit',{
                action: 'pass',
                goods_no: row.goods_no
            },resp=>{
                if (resp.code == 1) {
                    this.getTableData();
                    this.$message({
                        type: 'success',
                        message: '操作成功'
                    });
                } else if (resp.code == 0) {
                    this.$message({
                        type: 'warning',
                        message: resp.msg
                    });
                }
            });
        },

        /**
         * 审核不通过
         */
        fnSetAuditError (row) {
            this.$prompt('请输入审核不通过的理由', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
            }).then(({ value }) => {
                if(value == '') {
                    this.$message({
                        type: 'warning',
                        message: '内容不可以为空'
                    });
                    return;
                }
                this.$post('/student/shop_goods%5Caudit',{
                    action: 'fail',
                    goods_no: row.goods_no,
                    reason: value
                },resp=>{
                    if (resp.code == 1) {
                        this.getTableData();
                        this.$message({
                            type: 'success',
                            message: '操作成功'
                        });
                    } else if (resp.code == 0) {
                        this.$message({
                            type: 'warning',
                            message: resp.msg
                        });
                    }
                });
            });
        },

        /**
         * 设置限制
         */
        fnSetLimit (row) {
            this.goods_no = row.goods_no;
            this.$post('/student/shop_goods_bargain%5Cget_bargain',{
                goods_no: row.goods_no,
            },resp=>{
                if (resp.code == 1) {
                    this.ruleForm = {
                        bargain_duration: resp.data.bargain_duration,
                        bargain_times: resp.data.bargain_times,
                        bargain_limit: resp.data.bargain_limit,
                        bargain_product_json: resp.data.bargain_product_list
                    };

                    // 持续砍价时间处理
                    if(resp.data.bargain_duration == 86400) {
                        this.$set(this.exprice, 'second', this.getDate(0));
                        this.$set(this.exprice, 'date', 1);
                    } else if (resp.data.bargain_duration < 86400) {
                        let time = this.minuteFormate(resp.data.bargain_duration, false);

                        this.$set(this.exprice, 'date', 0);
                        this.$set(this.exprice, 'second', time );
                    } else if (resp.data.bargain_duration > 86400) {
                        let time = this.minuteFormate(resp.data.bargain_duration, true);

                        this.$set(this.exprice, 'date', Math.floor(resp.data.bargain_duration / 60 / 60 / 24));
                        this.$set(this.exprice, 'second', time );
                    }
                } else if (resp.code == 0) {
                    this.$message({
                        type: 'warning',
                        message: resp.msg
                    });
                }
            });
            this.dialogBargNumber = !this.dialogBargNumber;
        },

        /**
         * 批量填充次数
         */
        fnSetProduct (row) {
            if(row) {
                this.ruleForm.bargain_product_json.forEach(option => {
                    option.bargain_times = Number(row);
                });
            } else {
                this.$notify({
                    title: '提示',
                    message: '请填写正确的需砍次数',
                    type: 'warning',
                    duration: 2000
                });
            }
        },

        /**
         * 确定设置
         */
        fnSetBain (formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    this.$post('/student/shop_goods_bargain%5Cset_bargain',{
                        goods_no: this.goods_no,
                        bargain_times: this.ruleForm.bargain_times,
                        bargain_limit: this.ruleForm.bargain_limit,
                        bargain_duration: this.ruleForm.bargain_duration,
                        bargain_product_json: JSON.stringify(this.ruleForm.bargain_product_json)
                    },resp=>{
                        if (resp.code == 1) {
                            this.$message({
                                type: 'success',
                                message: '设置成功'
                            });
                            this.getTableData();
                            this.dialogBargNumber = !this.dialogBargNumber;
                        } else if (resp.code == 0) {
                            this.$message({
                                type: 'warning',
                                message: resp.msg
                            });
                        }
                    });
                } else {
                    console.log('error submit!!');
                    return false;
                }
            });
        },

        /**
         * 指定范围时间戳转换小时/分钟/秒
         * @param   {val}           Number      //时间戳
         * @param   {Booleanc}      type        //false:小时/分钟/秒  true:天/小时/分钟/秒
         */
        minuteFormate(val, type){
            let now_time = this.getDate(0);

            if(!type) {
                let min_total = Math.floor(val / 60);
                let sec = Math.floor(val % 60);

                if(min_total < 60){
                    return min_total * 60 * 1000 + sec * 1000 + now_time;
                }else{
                    let hour_total = Math.floor(min_total / 60);
                    let min = Math.floor(min_total % 60);

                    return hour_total * 60 * 60 * 1000 + min * 60 * 1000 + sec * 1000 + now_time;
                }
            } else {
                let hous = Math.floor(val / 60 / 60 / 24);
                let scend = val - hous * 86400;
                let min_total = Math.floor(scend / 60);
                let sec = Math.floor(scend % 60);

                if(min_total < 60){
                    return min_total * 60 * 1000 + sec * 1000 + now_time;
                }else{
                    let hour_total = Math.floor(min_total / 60);
                    let min = Math.floor(min_total % 60);

                    return hous * 24 * 60 * 60 * 1000 + hour_total * 60 * 60 * 1000 + min * 60 * 1000 + sec * 1000 + now_time;
                }
            }
        },

        /**
         * 获取指定日期时间戳
         */
        getDate (day) {
            let tempDate = new Date();
            let retult_milliseconds = tempDate.getTime() + 1000 * 60 * 60 * 24 * day;

            tempDate.setTime(retult_milliseconds);

            let result_Year = tempDate.getFullYear(),
                result_Month = (tempDate.getMonth() + 1).toString(),
                result_Date = tempDate.getDate().toString();

            if (result_Month.length === 1) {
                result_Month = "0" + result_Month;
            }

            if (result_Date.length === 1) {
                result_Date = "0" + result_Date;
            }

            let date = result_Year + "-" + result_Month + "-" + result_Date + " " + "00:00:00";

            return new Date(date).getTime();
        },

        /**
         * 编辑商品
         */
        fnEditShop (row) {
            this.$post('/wei4/hire_user%5Cget_login_session_ticket', {
                hire_no: row.hire_no
            }, resp => {
                if (resp.code == 1) {
                    let url = `${this.$shopBaseUrl}/manage/market/good-edit-barg?no=${row.goods_no}&session_ticket=` + resp.data.session_ticket;

                    // if(window.location.host == 'phaadmin.wxhand.com') {
                    //     url = `http://cms.zsdx.cn/manage/market/good-edit-barg?no=${row.goods_no}&session_ticket=` + resp.data.session_ticket;
                    // }else{
                    //     url = `http://gt.wxhand.com/manage/market/good-edit-barg?no=${row.goods_no}&session_ticket=` + resp.data.session_ticket;
                    // }
                    window.open(url, '_blank');
                } else {
                    this.$message({
                        type: 'warning',
                        message: resp.msg,
                        center: true
                    });
                }
            });
        },

        /**
         * 数据排序
         */
        handleSortChanged(data) {
            let sortTypeMap = {
                ascending: 'asc',
                descending: 'desc'
            };

            let sortFieldMap = {
                goods_sale: 'goods_sale',
                goods_view: 'goods_view',
                create_time: 'create_time',
                goods_sort: 'goods_sort'
            };

            if (data.order) {
                this.filterData.sort_field = sortFieldMap[data.prop];
                this.filterData.sort_type = sortTypeMap[data.order];
            } else {
                this.filterData.sort_field = '';
                this.filterData.sort_type = '';
            }

            this.getTableData();
        },

        /**
         * 全选逻辑操作
         */
        fnSelect(selection) {
            if(selection.length == this.tableData.length) {
                this.checkedAll = true;
            }else{
                this.checkedAll = false;
            }
            if(selection.length > 0 && selection.length < this.tableData.length) {
                this.checkIndeterminate = true;
            }else{
                this.checkIndeterminate = false;
            }
        },
        fnSelectAllTop(selection) {
            if(selection.length > 0) {
                this.checkedAll = true;
            }else{
                this.checkedAll = false;
            }
            if(selection.length > 0 && selection.length < this.tableData.length) {
                this.checkIndeterminate = true;
            }else{
                this.checkIndeterminate = false;
            }
        },
        fnChangeChecked() {
            if(this.checkedAll){
                this.toggleSelection(1);
            }else{
                this.toggleSelection();
            }
        },
        toggleSelection(rows) {
            if (rows) {
                this.$refs.goodsBargList.toggleAllSelection();
            } else {
                this.$refs.goodsBargList.clearSelection();
            }
        },
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },

        /**
         * 查看图片
         * @param   {String}    images      //单图预览
         * @param   {Array}     images      //多图预览
         */
        fnShowPreview(images) {
            if(images && Object.prototype.toString.call(images) == '[object String]') {
                this.$refs.preview.show([
                    images
                ]);
            } else if (images && Object.prototype.toString.call(images) == '[object Array]') {
                this.$refs.preview.show(images);
            } else {
                this.$message({
                    type: 'warning',
                    message: '图片类型错误'
                });
            }
        },

        /**
         * 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        }
    }
};
</script>

<style lang="less" scoped>
    .container {
        background-color: #fff;
        padding: 10px 15px 0px 15px;
        display: flex;
        flex-direction: column;
        position: relative;
        width: 100%;
        .header-nav {
            position: relative;
            display: flex;
            flex-wrap: wrap;
            align-items: center;
            justify-content: space-between;
            .header-left, .header-right {
                display: flex;
                align-items: center;
                flex-wrap: wrap;
            }
            .header-new-box {
                display: flex;
                margin-right: 15px;
                align-items: center;
                color: #606266;
                margin-bottom: 10px;
                white-space: nowrap;
                &-title {
                    margin-right: 2px;
                    white-space: nowrap;
                }
            }
        }
        /* 表单 */
        .scope-price {
            width: 50px;
            height: 50px;
        }
        /* 字体高亮 */
        .cursor-font {
            color: rgb(64, 158, 255);
            cursor: pointer;
        }
        /* 分页 */
        .pagination-wrapper {
            padding-top: 10px;
            .el-pagination {
                float: right;
                padding: 0;
                background-color: transparent;
            }
        }
    }
    /* 排序 */
    .sort-wrap {
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        white-space: nowrap;
        .sort-spliter {
            width: 1px;
            height: 12px;
            background: rgba(235, 235, 235, 1);
            margin: 0 10px;
            }
            .btn-sort {
            font-size: 14px;
            line-height: 1;
            color: #ccc;
            &:hover {
                color: #20a0ff;
            }
        }
    }
    .el-button-left {
        margin-left: 40px;
    }
    .el-button-right {
        margin-right: 10px;
    }
    .zd-audit-wrap {
        display: flex;
        align-items: center;
        .wrap-success {
            width:6px;
            height:6px;
            background:rgba(76,217,100,1);
            border-radius: 50%;
            margin-right: 5px;
        }
        .wrap-error {
            width:6px;
            height:6px;
            background:rgba(255,48,48,1);
            border-radius: 50%;
            margin-right: 5px;
        }
        .wrap-loading {
            width:6px;
            height:6px;
            background:rgba(255,175,57,1);
            border-radius: 50%;
            margin-right: 5px;
        }
    }
    .wrap {
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        .wrap-button {
            width: 100%;
            height: 32px;
            display: flex;
            justify-content: center;
        }
    }
    .wrap-time {
        height: 32px;
        display: flex;
        align-items: center;
        &-text {
            color: #999999;
            font-size: 14px;
            margin-left: 24px;
        }
        &-dw {
            color: #999999;
            font-size: 14px;
            margin-left: 65px;
            margin-left: 5px;
        }
        .wrap-tips, .wrap-tips-add {
            color: #999999;
            font-size: 14px;
            margin-left: -22px;
            position: relative;
            z-index: 10;
        }
        .wrap-tips-add {
            margin-left: -22px;
        }
    }
    .spec-list-wrap {
        display: flex;
        width: 200px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
</style>
<style lang="less">
    .goodsBargList{
        .el-table__body-wrapper .el-table__body .el-table__row td {
            border-right: none;
        }
        .el-table__header-wrapper .el-table__header .has-gutter tr th {
            border-right: none;
        }
        .el-table .el-table_1_column_6  .cell {
            position: relative;
        }
        .el-range-editor--small .el-range-separator{
            padding: 0 1px !important;
        }
        .el-button+.el-button {
            margin-left: 0px;
        }
        .el-button {
            padding: 4px 0;
        }
        .el-dialog__header {
            padding-top: 10px;
            box-shadow:0px 1px 0px 0px rgba(233,233,233,1);
            display: flex;
            align-items: center;
            background: #FAFAFA;
            border-radius: 4px 4px 0 0;
            .el-dialog__title {
                font-weight: 500;
                color: #333;
                font-size: 14px;
            }
            .el-icon-close:before {
                color: rgb(194,194,194);
                font-size: 17px;
                font-weight: bold;
            }
            .el-dialog__headerbtn {
                top: 14px;
            }
        }
        .dialogBargNumber .el-dialog__body {
            padding: 30px 52px;
        }
        .el-form-item__label {
            line-height: 32px;
        }
        .dialogBargNumber .el-table__body-wrapper {
            max-height: 300px;
            height: auto;
            &::-webkit-scrollbar {
                width: 3px;
                border: 2px;
            }
        }
        .dialogBargNumber {
            .el-table__body-wrapper .el-table__body .el-table__row td {
                border-right: none;
            }
            .el-table__header-wrapper .el-table__header .has-gutter tr th {
                border-right: none;
            }
        }
        .wrap-time-day .el-input__inner {
            pointer-events: none;
        }
    }
</style>
